package org.jay.angla.chart;

import java.util.ArrayList;
import java.util.List;

import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.chart.PointStyle;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint.Align;

public class QAChart extends AbstractDemoChart {
	private XYMultipleSeriesDataset mDataset;
	private XYMultipleSeriesRenderer mRenderer;

	private XYSeries series;
	private XYSeries series1;
	private int index = 0;

	public QAChart() {
		super();
		mDataset = new XYMultipleSeriesDataset();
		mRenderer = new XYMultipleSeriesRenderer();

		int[] colors = new int[] { Color.RED, Color.GREEN };
		PointStyle[] styles = new PointStyle[] { PointStyle.CIRCLE,
				PointStyle.SQUARE };
		mRenderer = buildRenderer(colors, styles);
		((XYSeriesRenderer) mRenderer.getSeriesRendererAt(0))
				.setFillPoints(true);
		((XYSeriesRenderer) mRenderer.getSeriesRendererAt(1))
				.setFillPoints(true);

		mRenderer.setApplyBackgroundColor(true);
		mRenderer.setMarginsColor(Color.argb(0, 0xff, 0xff, 0xff));
		mRenderer.setChartTitleTextSize(30);
		mRenderer.setAxisTitleTextSize(25);
		mRenderer.setLegendTextSize(20);
		mRenderer.setMargins(new int[] { 50, 50, 50, 30 });
		mRenderer.setXLabelsColor(Color.WHITE);
		mRenderer.setYLabelsColor(0, Color.WHITE);

		setChartSettings(mRenderer, "", "吸光度(abs)", "浓度(ug/ml)", 0.000f,
				4.000f, 0.00f, 10.00f, Color.WHITE, Color.WHITE);
		mRenderer.setXLabels(6);
		mRenderer.setYLabels(5);
		mRenderer.setShowGrid(true);
		mRenderer.setXLabelsAlign(Align.RIGHT);
		mRenderer.setYLabelsAlign(Align.RIGHT);
		mRenderer.setYLabelsPadding(10);

		mRenderer.setZoomEnabled(false, false);

		mRenderer.setZoomEnabled(false);
		mRenderer.setClickEnabled(false);
		mRenderer.setPanEnabled(false, false);

		series = new XYSeries("DEMO");
		series1 = new XYSeries("EXPE");
	}

	public GraphicalView getChartView(Context context) {
		series.add(index, 4);
		index = index + 1;
		series.add(index, 2);
		index = index + 1;
		
		series1.add(0, 2);
		series1.add(1, 4);

		mDataset.addSeries(series);
		mDataset.addSeries(series1);

		return ChartFactory.getLineChartView(context, mDataset, mRenderer);
	}

	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return "QA Chart";
	}

	@Override
	public String getDesc() {
		// TODO Auto-generated method stub
		return "By JayZhang";
	}

	public void add() {
		series.add(index, 4);
		index = index + 1;
	}

	public GraphicalView createView(Context context) {
		// x.add(new double[] { 0.000f, 1.500f, 3.000f });
		// value.add(new double[] { 3.0f, 7.0f, 9.0f });

		int[] colors = new int[] { Color.argb(255, 240, 249, 200) };
		PointStyle[] styles = new PointStyle[] { PointStyle.CIRCLE, };
		XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);
		((XYSeriesRenderer) renderer.getSeriesRendererAt(0))
				.setFillPoints(true);
		renderer.setApplyBackgroundColor(true);
		renderer.setMarginsColor(Color.argb(0, 0xff, 0xff, 0xff));
		renderer.setChartTitleTextSize(30);
		renderer.setAxisTitleTextSize(25);
		// renderer.setLegendHeight(50);
		renderer.setLegendTextSize(20);
		renderer.setMargins(new int[] { 50, 50, 50, 30 });
		renderer.setXLabelsColor(Color.WHITE);
		renderer.setYLabelsColor(0, Color.WHITE);

		setChartSettings(renderer, "", "吸光度(abs)", "浓度(ug/ml)", 0.000f, 4.000f,
				0.00f, 10.00f, Color.WHITE, Color.WHITE);
		renderer.setXLabels(6);
		renderer.setYLabels(5);
		renderer.setShowGrid(true);
		renderer.setXLabelsAlign(Align.RIGHT);
		renderer.setYLabelsAlign(Align.RIGHT);
		renderer.setYLabelsPadding(10);

		renderer.setZoomEnabled(false, false);

		renderer.setZoomEnabled(false);
		renderer.setClickEnabled(false);
		renderer.setPanEnabled(false, false);

		String[] titles = new String[] { "样品" };

		// mDataset = buildDataset(titles, x, value);
		GraphicalView view = ChartFactory.getLineChartView(context, mDataset,
				renderer);
		return view;
	}

	@Override
	public Intent execute(Context context) {
		// TODO Auto-generated method stub
		return null;
	}

}
